package TestJVM;

import cn.hutool.core.util.RandomUtil;
import org.junit.jupiter.api.Test;

import java.util.Random;

/**
 * @Author Mr.Wen
 * @Version 1.0
 */
public class Test3 {
    public static void main(String[] args) {
        /*虚拟机试图使用的最大内存*/
        long l = Runtime.getRuntime().maxMemory();
        System.out.println("l = " + l / 1024 / 1024 + "MB");
        /*返回虚拟机的总内存*/
        long l2 = Runtime.getRuntime().totalMemory();
        System.out.println("l2 = " + l2 / 1024 / 1024 + "MB");
        long l3 = Runtime.getRuntime().freeMemory();
        System.out.println("l3 = " + l3 / 1024 / 1024 + "MB");
//        -Xms1024m -Xmx1024m -XX:+PrintGCDetails  可用于修改虚拟机内存参数
    }

    @Test/*性能测试*/
    void test() {
        long beginTime = System.currentTimeMillis();
        int i = 0;
        String str = "ashdklashdklas";
        while (i < 10000) {
            str += new Random().nextInt(999999999);
            System.out.println("str = " + str);
            i++;
        }
        long endTime = System.currentTimeMillis();
        System.out.println("程序运行时间：" + (endTime - beginTime) + "ms");
    }
}
